// 人员管理数据请求

function manageAdmin() {

    // 添加新增按钮点击事件
    addBtnAction();

    // 给搜索框添加点击事件
    queryBtnAction(pageClickAction);

    // 默认加载第一页数据
    pageClickAction();


    function pageClickAction() {

        if (!$('#keywords').val())var url = http_url + 'Admin/index?token=' + sessionStorage.token + '&page=' + curPage;
        else {
            var url = http_url + 'Admin/index?token=' + sessionStorage.token + '&page=' + curPage +'&keywords=' + $('#keywords').val();
        }

        // console.log(curPage);
        $.ajax({
            url: url,
            success: function (response) {
                if (response.code == 0) {
                    // $('#ele').find('li').remove();
                    $('tbody').find('tr').remove();
                    showAdmin(response, pageClickAction);
                }
            }

        });
    }

    function showAdmin(response, pageClickAction) {

        console.log(response);
        // 创建分页器
        createPagiantion(response, pageClickAction);

        // 展示数据
        var list = response.data.data;
        console.log('list');
        // list.reverse();
        list.forEach(function (data, index) {
            var tr = $('<tr/>').prop('tid', data.id);
            var td_id = $('<td/>').html((curPage - 1) * 10 + index + 1);
            var td_account = $('<td/>').html(data.account);
            var td_name = $('<td/>').html(data.name);
            var td_title = $('<td/>').html(data.title);
            var td_addtime = $('<td/>').html(timestampToTime(data.addtime));

            if (data.title != '超级管理员'){

            var td_action = $('<td/>').append($('<a/>').prop('href', "#").addClass('edit').html('编辑 '))
                .append($('<a/>').prop('href', "#").addClass('delete').html('删除 '))
                .append($('<a/>').prop('href', "#").addClass('reset').html('重置密码'));
            }
            else{
                var td_action = $('<td/>');
            }
            tr.append(td_id).append(td_account).append(td_name).append(td_title).append(td_addtime).append(td_action);
            $('#content_wrap table').append(tr);
        });

        editBtnAdmin();

        // 删除操作的地URL址
        var http_url_delete = http_url + 'Admin/delete?token=' + sessionStorage.token + '&id=';
        // 删除操作， 给 class = 'delete' 的 a 标签添加点击事件
        stateDelete($('.delete'), http_url_delete, manageAdmin);

        // 重置密码操作
        resetPassword();

    }

}
//--------------------------------------------编辑实现-------------------------------------
function editBtnAdmin() {
    $('.edit').click(function () {
        $.ajax({
            url: http_url + '?token' + sessionStorage.token + '&id' + $(this).parents('tr').prop('tid') ,
            type: 'GET',
            success: function (response) {
                if (response.code == 0) {
                    console.log(response);
                    showAdminInput(response);
                }
            }
        });

        $('#content_wrap').load('editAdmin_wy.html', function () {
            editAdmin();
        });
    });
    function editAdmin() {

    }
}